package ${basePackage}.api.${moduleName};

import ${basePackage}.api.BaseController;
import ${basePackage}.core.annotation.pr.PreventRepeat;
import ${basePackage}.core.model.ApiResponse;
import ${basePackage}.core.constants.Constants;
import ${basePackage}.core.model.PageData;
import ${basePackage}.core.model.PageWrap;
import ${basePackage}.dao.${moduleName}.model.${table.pascalCaseName};
import ${basePackage}.service.${moduleName}.${table.pascalCaseName}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "${table.comment}接口")
@RestController
@RequestMapping("/${moduleName}/${table.camelCaseName}")
public class ${table.pascalCaseName}Controller extends BaseController {

    @Autowired
    private ${table.pascalCaseName}Service ${table.camelCaseName}Service;

    @PreventRepeat
    @ApiOperation("新建")
    @PostMapping("/create")
<#if withPerm == 'true'>
    @RequiresPermissions("${moduleName}:${table.camelCaseName}:create")
</#if>
    public ApiResponse<Integer> create(@Validated(Constants.OperaType.Create.class) @RequestBody ${table.pascalCaseName} param) {
        return ApiResponse.success(${table.camelCaseName}Service.create(param));
    }

    @ApiOperation("删除")
    @GetMapping("/delete/{id}")
<#if withPerm == 'true'>
    @RequiresPermissions("${moduleName}:${table.camelCaseName}:delete")
</#if>
    public ApiResponse<?> deleteById(@PathVariable Integer id) {
        ${table.camelCaseName}Service.deleteById(id);
        return ApiResponse.success(null);
    }

    @ApiOperation("批量删除")
    @GetMapping("/delete/batch")
<#if withPerm == 'true'>
    @RequiresPermissions("${moduleName}:${table.camelCaseName}:delete")
</#if>
    public ApiResponse<?> deleteByIdInBatch(@RequestParam String ids) {
        ${table.camelCaseName}Service.deleteByIdInBatch(this.getIdList(ids));
        return ApiResponse.success(null);
    }

    @ApiOperation("修改")
    @PostMapping("/updateById")
<#if withPerm == 'true'>
    @RequiresPermissions("${moduleName}:${table.camelCaseName}:update")
</#if>
    public ApiResponse<?> updateById(@Validated(Constants.OperaType.Update.class) @RequestBody ${table.pascalCaseName} param) {
        ${table.camelCaseName}Service.updateById(param);
        return ApiResponse.success(null);
    }

    @ApiOperation("批量修改")
    @PostMapping("/updateByIdInBatch")
<#if withPerm == 'true'>
    @RequiresPermissions("${moduleName}:${table.camelCaseName}:update")
</#if>
    public ApiResponse<?> updateById(@RequestBody List<${table.pascalCaseName}> param) {
        ${table.camelCaseName}Service.updateByIdInBatch(param);
        return ApiResponse.success(null);
    }

    @ApiOperation("分页查询")
    @PostMapping("/page")
<#if withPerm == 'true'>
    @RequiresPermissions("${moduleName}:${table.camelCaseName}:query")
</#if>
    public ApiResponse<PageData<${table.pascalCaseName}>> findPage (@RequestBody PageWrap<${table.pascalCaseName}> pageWrap) {
        return ApiResponse.success(${table.camelCaseName}Service.findPage(pageWrap));
    }
}
